const path = require("path")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
  entry: path.resolve(__dirname, "../src/index.js"),
  output: {
    path: path.resolve(__dirname, "../build"),
    filename: "./js/index.js",
    publicPath:"/"
  },
  module: {
    rules: [
      {//HTML-loader配置
        test: /\.ejs$/i,
        loader: "ejs-loader",
        options:{
          variable:'data'
        }
      },{
        test:/\.css$/i,
        use:['style-loader','css-loader']
      }]
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: path.resolve(__dirname, "../public/index.html"),
      minify: {
        collapseWhitespace: true,
        keepClosingSlash: true,
        removeComments: true,
        removeRedundantAttributes: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
        useShortDoctype: true
      }
    }),
    new CopyWebpackPlugin({
      patterns: [{
        from: path.resolve(__dirname, "../public"),
        to: "public",
        globOptions: {
          ignore: ["**/index.html"]
        }
      }]
    })
  ],
  resolve: {
    alias: {
      $v: path.resolve(__dirname, "../src/views"),
      $r: path.resolve(__dirname, "../src/router"),
      $a: path.resolve(__dirname, "../src/api"),
    },
    extensions:['.js','.css','.ejs']
  },

  mode: "production"

}